#include <stdio.h>
#include <gtk/gtk.h>

#include "ui_main.h"
#include "ui_task.h"

static GObject *window;

static void confirm_handler(GtkWidget *widget, gpointer userdata)
{
    ShowConfirmInfo(GTK_WIDGET(window), userdata);
}

static void error_handler(GtkWidget *widget, gpointer userdata)
{
    ShowErrorInfo(GTK_WIDGET(window), userdata);
}


static int InitButtons(GtkBuilder *builder)
{
    GObject *add = NULL, *remove = NULL, *resume = NULL, *pause = NULL;
    

    add = gtk_builder_get_object(builder, "add_button");
    remove = gtk_builder_get_object(builder, "remove_button");
    resume = gtk_builder_get_object(builder, "resume_button");
    pause = gtk_builder_get_object(builder, "pause_button");

    
    g_signal_connect(add, "clicked", G_CALLBACK(OpenNewTaskWindow), "测试消息");
    g_signal_connect(remove, "clicked", G_CALLBACK(RemoveSlectedTask), "按钮2");
    g_signal_connect(resume, "clicked", G_CALLBACK(StartDownladTask), "按钮3");
    g_signal_connect(pause, "clicked", G_CALLBACK(StopDownloadingTask), "按钮4");
}

void GtkMain(int argc, char **argv)
{
    gtk_init(&argc, &argv);

    GtkBuilder *builder = OpenUiFile("gtkdown.ui", &window, 1);
    if(!builder){
        g_abort();
    }
    
    InitButtons(builder);
    InitTaskList(builder);

    gtk_main();
    
    FreeTaskList();
}